/**
 * com.dingjian.basedata.org.controller.PositionListController.java
 */
package com.dingjian.basedata.org.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.dingjian.base.CoreEntity;
import com.dingjian.base.service.BaseService;
import com.dingjian.base.util.StringUtils;
import com.dingjian.basedata.org.model.JobLevel;
import com.dingjian.basedata.org.model.Position;
import com.dingjian.basedata.org.service.PositionService;
import com.dingjian.framework.base.controller.ListController;

/**
 * @author FengMy
 * 
 * @since 2012-10-10
 */
@Controller
@RequestMapping(value="basedata/position/*")
public class PositionListController extends ListController {
	@Autowired
	private PositionService positionService;
	@Override
	protected CoreEntity createNewEntity() {
		return null;
	}

	@Override
	protected String getListView() {
		return null;
	}

	@Override
	protected String getEditView() {
		return null;
	}

	@Override
	protected String getListMapper() {
		return null;
	}

	@Override
	protected BaseService<Position> getService() {
		return positionService;
	}
	
	@RequestMapping(value="getByOrg")
	public void getByOrg(HttpServletResponse response){
		List<Position> pos = new ArrayList<Position>();
		String org = getString("org");
		if(!StringUtils.isEmpty(org)){
			pos = positionService.getByOrg(org);
		}
		outPrint(response, JSONArray.fromObject(pos, getDefaultJsonConfig()));
	}
	
	@RequestMapping(value="getJobLevelByPosition")
	public void getJobLevelByPosition(HttpServletResponse response){
		List<JobLevel> jls = new ArrayList<JobLevel>();
		String position = getString("position");
		if(!StringUtils.isEmpty(position)){
			Position pos = positionService.getEntityById(position);
			Map<String,Object> param = new HashMap<String, Object>();
			param.put("job", pos.getJob().getId());
			jls = queryExecutor.execQuery("com.dingjian.basedata.org.dao.JobLevelDao.select", param, JobLevel.class);
		}
		outPrint(response, JSONArray.fromObject(jls, getDefaultJsonConfig()));
	}
}
